package cn.group.service.impl;

import cn.group.dao.SCDao;
import cn.group.domain.SC;
import cn.group.domain.Student;
import cn.group.service.SCService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SCServiceImpl implements SCService {
    private SCDao scDao;
    @Autowired
    public SCServiceImpl(SCDao scDao){
        this.scDao=scDao;
    }
    @Override
    public List<SC> getAll() {
        List<SC> scs = scDao.queryAllSC();
    /*    for (SC sc : scs) {
            System.out.println(sc);
        }*/
        return scs;
    }

    @Override
    public PageInfo<SC> getAllStu(Integer currentPage, Integer pageSize,Integer id) {
        PageHelper.startPage(currentPage,pageSize);
        List<SC> scList=scDao.queryStuId(id);
        System.out.println(scList.size());
        PageInfo<SC> pageInfo=new PageInfo<>(scList);
        return pageInfo;
    }

    @Override
    public PageInfo<SC> queryAll(Integer currentPage, Integer pageSize) {
        PageHelper.startPage(currentPage,pageSize);
        List<SC> scList=scDao.queryAllSC();
        System.out.println(scList.size());
        PageInfo<SC> pageInfo=new PageInfo<>(scList);
        return pageInfo;
    }

    @Override
    public SC getOneById(Integer id) {
        SC sc=scDao.queryById(id);
        return sc;
    }

    @Override
    public boolean addOne(Integer sid,Integer cid ,Integer score) {
        int result=scDao.insertBySC(sid,cid,score);
        return result>0;
    }

    @Override
    public boolean removeOne(SC sc) {
        int result=scDao.deleteBySC(sc);
        return result>0;
    }

    @Override
    public boolean changeOne(SC sc) {
        int result=scDao.updateBySC(sc);
        return result>0;
    }

    /*获得该班主任的班级的成绩*/
    @Override
    public PageInfo<SC> queryByHteacherId(Integer currentPage, Integer pageSize, Integer id) {
        PageHelper.startPage(currentPage,pageSize);
        List<SC> scList=scDao.queryByHTId(id);
        //System.out.println(scList.size());
        PageInfo<SC> pageInfo=new PageInfo<>(scList);
        return pageInfo;
    }

    /*获得该任课老师所教课程的成绩*/
    @Override
    public PageInfo<SC> queryBytteacherId(Integer currentPage, Integer pageSize, Integer id) {
        PageHelper.startPage(currentPage,pageSize);
        List<SC> scList=scDao.queryByTTId(id);
        //System.out.println(scList.size());
        PageInfo<SC> pageInfo=new PageInfo<>(scList);
        return pageInfo;
    }
}
